home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / GRAPHICS.SWG / 0095_Starry night simulation.pas < prev    next >
Pascal/Delphi Source File  |  1994-05-25  |  6KB  |  219 lines

  1.  
  2. Program StarryNight;
  3.  
  4. { Looks like some late evening in the summer before starry night }
  5. { But i guess that stars goes brighter much faster than dimmer   }
  6. { Can you advise me on that fenomenon?                           }
  7.  
  8. Const
  9.   NumberOfStars = 55; { Number of Stars. Can't be greater than 55 }
  10. type
  11.   StarMapArray = Array [0..6,0..4] of Word;
  12.   { Each star allocate rectangle 4 pixels width and 6 pixels height }
  13. const
  14.    StarMap : StarMapArray =
  15.          ((0,0,1,0,0),
  16.           (0,0,2,0,0),
  17.           (0,0,3,0,0),
  18.           (1,3,4,3,1),
  19.           (0,0,3,0,0),
  20.           (0,0,2,0,0),
  21.           (0,0,1,0,0));
  22.   { This is picture of one star }
  23. Type
  24.  
  25.   RGBRec = Record
  26.     r,g,b: byte;
  27.   end;
  28.   { Palette record }
  29.  
  30.   PStar = ^TStar;   { Star itself }
  31.   TStar = object
  32.     Delta: byte;       { Step for brightness change }
  33.     Brightest: RGBRec; { The very brightest color of the star }
  34.     Brighten: Boolean; { Do star go brighter? }
  35.     Number: byte;      { Personal star number }
  36.     Xloc,Yloc: word;   { X,Y location }
  37.     Colors: Array [1..4] of RGBRec;  { Star colors }
  38.     constructor Init(ANumber: Byte);
  39.     procedure Relocate;              { Move star to new position }
  40.     procedure Rotate;                { Change colors step by step }
  41.   end;
  42.  
  43. {..$DEFINE Mono}
  44. { Define MONO if you whant to see gray-scaled stars }
  45.  
  46. function keypressed : boolean; assembler;
  47.   asm
  48.     Mov AH,01h
  49.     Int 16h
  50.     JNZ @0
  51.     XOR AX,AX
  52.     Jmp @1
  53. @0: Mov AL,1
  54. @1:
  55.   end;
  56.  
  57. constructor TStar.Init(ANumber: Byte);
  58.   var
  59.     cx,cy: word;
  60.   begin
  61.     Number:=ANumber;
  62.     XLoc:=0;YLoc:=0;
  63.     Relocate;
  64.   end;
  65.  
  66. procedure TStar.Relocate;
  67.   var
  68.     cx,cy: word;
  69.     cc: byte;
  70.     {$IFDEF Mono}
  71.     mc: byte;
  72.     {$ENDIF}
  73.   begin
  74.     For cy:=0 to 6 do
  75.       For cx:=0 to 4 do
  76.         Mem[$A000:(cx+XLoc)+(cy+Yloc)*320]:=(224+(cy+YLoc) div 8);
  77.     { Restore old background }
  78.     Brighten:=True;
  79.     {$IFDEF Mono}
  80.     mc:=Random(64);
  81.     With Brightest do
  82.       begin
  83.         r:=mc;
  84.         g:=mc;
  85.         b:=mc;
  86.       end;
  87.     {$ELSE}
  88.     With Brightest do
  89.       begin
  90.         r:=Random(64);
  91.         g:=Random(64);
  92.         b:=Random(64);
  93.       end;
  94.     {$ENDIF}
  95.     Port[968]:=Number*4;
  96.     For cc:=1 to 4 do
  97.       begin
  98.         with Colors[cc] do
  99.           begin
  100.             r:=0; g:=0; b:=0;
  101.           end;
  102.         Port[969]:=0;
  103.         Port[969]:=0;
  104.         Port[969]:=0;
  105.       end;
  106.     XLoc:=Random(320-5);
  107.     YLoc:=Random(200-7);
  108.     Delta:=Random(5)+1;
  109.     { Delta:=(YLoc Div 40)+1;}
  110.     { Stars near horizont blink rapidly }
  111.     For cx:=0 to 4 do
  112.       For cy:=0 to 6 do
  113.         if StarMap[cy,cx]<>0
  114.            then
  115.              Mem[$A000:(cx+XLoc)+(cy+Yloc)*320]:=
  116.                  StarMap[cy,cx]+(Number ShL 2)-1;
  117.     { Put star to screen }
  118.   end;
  119.  
  120. procedure TStar.Rotate;
  121.   var
  122.     cc: byte;
  123.     cx,cy: word;
  124.   begin
  125.     If Brighten
  126.        then
  127.          begin
  128.            For cc:=1 to 4 do
  129.              begin
  130.                If Colors[5-cc].r+Delta<=Brightest.r div cc
  131.                   then
  132.                     Inc(Colors[5-cc].r,Delta)
  133.                   else
  134.                     Colors[5-cc].r:=Brightest.r div cc;
  135.                If Colors[5-cc].g+Delta<=Brightest.g div cc
  136.                   then
  137.                     Inc(Colors[5-cc].g,Delta)
  138.                   else
  139.                     Colors[5-cc].g:=Brightest.g  div cc;
  140.                If Colors[5-cc].b+Delta<=Brightest.b div cc
  141.                   then
  142.                     Inc(Colors[5-cc].b,Delta)
  143.                   else
  144.                     Colors[5-cc].b:=Brightest.b div cc;
  145.              end;
  146.            if (Colors[4].r=Brightest.r) and
  147.               (Colors[4].g=Brightest.g) and
  148.               (Colors[4].b=Brightest.b)
  149.               then
  150.                 Brighten:=False
  151.          end
  152.        else
  153.          begin
  154.            For cc:=1 to 4 do
  155.              begin
  156.                If Colors[cc].r>=Delta
  157.                   then
  158.                     Dec(Colors[cc].r,Delta)
  159.                   else
  160.                     Colors[cc].r:=0;
  161.                If Colors[cc].g>=Delta
  162.                   then
  163.                     Dec(Colors[cc].g,Delta)
  164.                   else
  165.                     Colors[cc].g:=0;
  166.                If Colors[cc].b>=Delta
  167.                   then
  168.                     Dec(Colors[cc].b,Delta)
  169.                   else
  170.                     Colors[cc].b:=0;
  171.              end;
  172.            if (Colors[4].r=0) and (Colors[4].g=0) and (Colors[4].b=0)
  173.               then
  174.                 Relocate;
  175.          end;
  176.       Port[968]:=Number*4;
  177.       For cc:=1 to 4 do
  178.         begin
  179.           Port[969]:=Colors[cc].r;
  180.           Port[969]:=Colors[cc].g;
  181.           Port[969]:=Colors[cc].b;
  182.         end;
  183.   end;
  184.  
  185. var
  186.   StarArray: Array [1..NumberOfStars] of PStar;
  187.   sc: byte;
  188.   c: char;
  189.   ccx,ccy: word;
  190.  
  191. begin
  192.   asm mov ax,13h; int 10h end;
  193.   port[968]:=224;
  194.   for ccx:=1 to 255-224 do
  195.     begin
  196.       port[969]:=ccx div 2;
  197.       port[969]:=0;
  198.       port[969]:=ccx;
  199.     end;
  200.   For ccx:=0 to 319 do
  201.     For ccy:=0 to 199 do
  202.       Mem[$A000:(ccx+ccy*320)]:=(224+ccy div 8);
  203.   { This make a background or backsky as you like }
  204.  
  205.   for sc:=1 to NumberOfStars do
  206.     begin
  207.       StarArray[sc]:=New(PStar,Init(sc));
  208.     end;
  209.   sc:=1;
  210.   repeat
  211.     StarArray[sc]^.Rotate;
  212.     If sc=NumberOfStars
  213.        then
  214.          sc:=1
  215.        else
  216.          Inc(sc);
  217.   until keypressed;
  218. end.
  219.